#【练习】购物车

class Shopcart():
    def __init__(self,product_list):
        self.product_list=product_list
    def add_product(self,product):
        """
        添加功能
        :param product: 商品
        :return:
        """
        self.product_list.append(product)
    def reveal_product(self):
        for product in self.product_list:
            print(product)


class Product():
    def __init__(self,name,price):
        self.name=name
        self.price=price
    def __str__(self):
        return f"商品名:{self.name},商品价格:{self.price}"
    def add_cart(self,shopcart:Shopcart):
        shopcart.add_product(self)



if __name__ == '__main__':
    product1=Product("Tomato",2)
    product2=Product("banana",1.5)
    product_list=[]
    Sc=Shopcart(product_list)

    product1.add_cart(Sc)
    product2.add_cart(Sc)

    Sc.reveal_product()
